
#include "Logic/InstancedSkeletalMeshComponent.h"

int32 UInstancedSkeletalMeshComponent::AddInstance(const FTransform& Transform, UAnimSequenceBase* InAnimation)
{
	int32 Result = CurrentIndex;
	CurrentIndex += 1;
	TSharedPtr<FSkeletalInstancedProxy> Proxy = MakeShared<FSkeletalInstancedProxy>();
	InstancedProxyMap.Add(Result, Proxy);
	Proxy->UpdateTransform(FTransform3f(Transform) );
	Proxy->PlayAnimSequence(InAnimation);
	return Result;
}

void UInstancedSkeletalMeshComponent::UpdateInstanceTransform(int32 InstanceIndex, const FTransform& Transform)
{
	if(auto Proxy = InstancedProxyMap.Find(InstanceIndex))
	{
		Proxy->Get()->UpdateTransform( FTransform3f(Transform) );
	}
}

void UInstancedSkeletalMeshComponent::UpdateInstanceAnimation(int32 InstanceIndex, UAnimSequenceBase* InAnimation)
{
	if(auto Proxy = InstancedProxyMap.Find(InstanceIndex))
	{
		Proxy->Get()->PlayAnimSequence( InAnimation );
	}
}

void UInstancedSkeletalMeshComponent::RemoveInstance(int32 InstanceIndex)
{
	InstancedProxyMap.Remove(InstanceIndex);
}